package com.ccjq.shosestore.web.controller.member;

import com.ccjq.shosestore.member.service.UserService;
import com.ccjq.shosestore.member.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 用户名校验
 */
public class UserExistCheckServlet extends HttpServlet {
    /**
     * 调用servic接口
     */
    private UserService userService = new UserServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        boolean count = userService.exists(username);
        if(count){
            System.out.println("=====> 用户名:" + username +"已注册");
        }else {
            System.out.println("=====> 用户名:" + username +"未注册");
        }
        PrintWriter out = response.getWriter();
        String resule = "{\"code\":"+ count + "}";
        out.println(resule);
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
